﻿using System;
using System.Linq;
using System.Web.UI;

namespace ASPNETVN.PORTAL.Components.Share.Controls
{
    public partial class CommentList : UserControl
    {
        public string Title { set; get; }
        public bool IsRequireApproved { set; get; }

        public void Reload()
        {
            LoadComments(); 
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                LoadComments();
            }
        }

        private void LoadComments()
        {
            int itemID = Convert.ToInt32(Request.QueryString["itemid"]);
            Guid moduleID = new Guid(Request.QueryString["mid"]);

            var comments = Comment.SelectCollectionBy_ModuleID_ItemID(moduleID, itemID);
            if (this.IsRequireApproved)
            {
                DataListComments.DataSource = comments.Where(x => x.Status).OrderByDescending(x => x.CreatedDate);
            }
            else
            {
                DataListComments.DataSource = comments.OrderByDescending(x => x.CreatedDate);
            }
            DataListComments.DataBind();
        }
    }
}